﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

public partial class ViewImages : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private Image DrawReflection(Image img, Color toBG) // img is the original image.
    {
        //This is the static function that generates the reflection...
        int height = img.Height + 100; //Added height from the original height of the image.
        Bitmap bmp = new Bitmap(img.Width, height, PixelFormat.Format64bppPArgb); //A new 
        //bitmap.
        //The Brush that generates the fading effect to a specific color of your background.
        Brush brsh = new LinearGradientBrush(new Rectangle(0, 0, img.Width + 10,
          height), Color.Transparent, toBG, LinearGradientMode.Vertical);
        bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution); //Sets the new 
        //bitmap's resolution.
        using (Graphics grfx = Graphics.FromImage(bmp)) //A graphics to be generated 
        //from an image (here, the new Bitmap we've created (BMP)).
        {
            Bitmap bm = (Bitmap)img; //Generates a bitmap from the original image (img).
            grfx.DrawImage(bm, 0, 0, img.Width, img.Height); //Draws the generated 
            //bitmap (bm) to the new bitmap (bmp).
            Bitmap bm1 = (Bitmap)img; 	//Generates a bitmap again 
            //from the original image (img).
            bm1.RotateFlip(RotateFlipType.Rotate180FlipX); //Flips and rotates the 
            //image (bm1).
            grfx.DrawImage(bm1, 0, img.Height); 	//Draws (bm1) below (bm) so it serves 
            //as the reflection image.
            Rectangle rt = new Rectangle(0, img.Height, img.Width, img.Height/2); //A new rectangle 
            //to paint our gradient effect.
            grfx.FillRectangle(brsh, rt); //Brushes the gradient on (rt).
        }
        return bmp; //Returns the (bmp) with the generated image.
    }

}
